/* Henry Jartu IV
 * Created July 25, 2012 
 * Redefined July 1, 2013
 * Pg 697
 * Question 18
 * 
 * Titled Store Inventory 
 *
 * This appilcation will be able to keep record of a stores inventory and also tracks the 
 * transactions of the store. At thene end of a week the application will be able to 
 * print out a report of that weeks transactions and inventory. 
 * 
 *
 */
package term.progect;

import java.io.*;
import java.util.*;
import javax.swing.*;


/**
 *
 * @author JartuIV
 */
public class TermProgect {
  static Scanner ikey = new Scanner(System.in); 
    
  static int TotalItemsSold = 150;
  static int PStoreLocation = 0;
  static double ItemsSold = 0; 
  static double currentprice = 0;
  static int SellingPriceLocation = 2;
  static int Initcount = 0;
  static double [][] currentItemInventory  = new double [5][6];
  static double TotalInventoryPrice = 0;
  static double TotalMaxtrixInventoryPrice = 0;
  static double RunningTotalMaxtrix = 0;
  static double TotalNumItemsInStore = 0;
  static double BeginningInventory = 0; 
                

 
  /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
         throws FileNotFoundException                           
    {
    
         //InitalizeStoreArray IAS = new InitalizeStoreArray();
         // Store RTS = new Store();
          
          
         String[] ItemName = new String[5];       
               
         int[] pOrdered = new int[5];
         int[] ItemID = new int[5];
         int pSold [] = new int[5];
         int   pInStore[] = new int[5];
         double[] manfacPrice = new double[5];
         double[] sellPrice=  new double[5];      
         double Total = 0;
         int  Totalitems  = 0;
         int NumItemsStored = 0;
         int Instore;
         int PStore = 0;
 
         String[][] Items = {{"4444","Circular Saw"},{"3333","Cooking Range"},{"3685","Dog Food"},{"2231","Ball Pens"},{"1503","Bose Speakers"}};
        double[][] ItemInventory = {{150,45,125,0,0,0}
                                ,{50,20,450,0,0,0},{30,55,75,0,0,0},{100,15,25,0,0,0},{30,800,1200,0,0,0}};
        
          IntializeCurrentStoreArray(ItemInventory , Items, 0 , 0 ); 
 
        int Assignum;
        do
        {
            
          //Here I am running a do...while Loop for my menu options.
          //"3" will be used for Checking availability.
          //"2" will be used to purchase an item.
          //"1" will be used to Print an invetory report of that weeks sells and stock.
          //"0" will be used to exit the program.  
            String Fire = JOptionPane.showInputDialog("Enter 3 to Determine Stock of an item. " + "\n"+
                                                      "Enter 2 to Purchse an item. " + "\n"+
                                                      "Enter 1 to Print a report Inventory. "+ "\n"+
                                                      "Enter 0 to Exit this application. ");
            
            
            Assignum = Integer.parseInt(Fire);
            
            //I am using if statements to check which option to user enter.
            
             
        if(Assignum == 3)
            {
                
        int CA = 0;      
        String lost = JOptionPane.showInputDialog("Enter ItemID for availibility. ");
        Instore = Integer.parseInt(lost);
        
       ItemSearch(ItemInventory , Items , Instore , 0);
          
            }
                 
        
       if(Assignum == 2)
            {
             //The User will enter which item they would like to purchase.
             //The Item ID will be entered here to find the product.
            
             /* A background process will be taking place to tell the user whether the  
              * item is in stock or out of stock. A Show message dialog box will display that
              * the item is instock or out of stock.
              * After that the user will be prompted to enter how many they would like to
              * purchase. 
              */
                
                
              //IAS will reduce inventory 
        
             String lost = JOptionPane.showInputDialog("Please enter ItemID");
             int Sell3 = Integer.parseInt(lost);
             
             String lost2 =JOptionPane.showInputDialog("How many would you like to purchase?");
             int Sell2 = Integer.parseInt(lost2);
             
             
             IntializeCurrentStoreArray(ItemInventory , Items, Sell3 , Sell2 );
             //IAS.ReduceProdInv(lost , Sell2);
             
            }
            
            
            //Here this if statement will print out a up to date report of the store inventory.
            //I will implent the time and date for the user to see when it was printed. 
                          
      if(Assignum == 1)
            {     
               
               printMatrix1(currentItemInventory, Items);
                
       
            }
                
          
        
        
       
           {
      
                 
                
        }  
      //After the last if statement the user will be sent back to the menu option.
      //The user will be constantly sent back after each statement until "0" is entered. 
    }
           while(Assignum <=-1  || Assignum > 0.5);
        //System.out.println(IAS.ReduceInv(TotalItemsSold));
        
   //IntializeCurrentStoreArray(  double [][] matrix, String [][] ItemsMatrix , int ItemID , int currentPiecesSold )
   //IntializeCurrentStoreArray(ItemInventory , Items, 0 , 0 );     
     

 
}
  //Here I am creating method to print a two dimensional array for my the Inventory report. 
  //This print Matrix has 25 blocks.
 
  /*
   * This array named "Matrix" has 5 rows and and 3 colums at first.
   * The 5 rows are each item in the array.
   * The colums are named:
   * 1. Number of Pieces ordered.
   * 2. Manufacturing Price.
   * 3. Selling Price.
   */
    
    public static void printMatrix1(double [][] currentItemInventory , String [][] Itemss)
  {
      
      
   System.out.println("                  Friendly Hardware Store");  
   System.out.println(" ");
   System.out.println("ItemID" +  "\t" + "ItemName" + "\t" + "pOrdered"
                     +  "\t" + "PinStore" +  "\t" + "pSold" +  "\t" + 
                     "ManufPrice" +  "\t" + "SellingPrice");
   
     for( int row = 0; row < currentItemInventory.length; row++)
      
     {
        
        System.out.println(Itemss[row][0] + "\t" + Itemss[row][1] + "\t" + currentItemInventory[row][0] +
            "\t" + "\t" +  currentItemInventory[row][3]+"\t" + "\t" +  currentItemInventory[row][4] + "\t" +  currentItemInventory[row][1]
                +"\t" + "\t" +  currentItemInventory[row][2]);
       
     }
	 
     BeginningInventory = BeginningInventory - TotalNumItemsInStore;
   System.out.println("Total Number of Items in store " + BeginningInventory);
   TotalMaxtrixInventoryPrice = TotalMaxtrixInventoryPrice - RunningTotalMaxtrix;
   System.out.println("Total Number in store Price $" + TotalMaxtrixInventoryPrice);
 
  }
    
     public static void IncItemssoldCount( double x)
   {    
     ItemsSold = ItemsSold + x;
   }
        //This method has 4 items being passed through.
        //The two arrays being passed come from the main method under the names Items andItemsInventory.
        
        public static void IntializeCurrentStoreArray(  double [][] matrix, String [][] ItemsMatrix , int ItemID , int currentPiecesSold )
        {
         
            // String SHolder;
           //  int IHolder;
            
        if(Initcount == 0)   
        {
     for( int row = 0; row < matrix.length; row++)
      
     {
          TotalInventoryPrice = matrix[row][0] * matrix[row][2];
          TotalMaxtrixInventoryPrice =  TotalMaxtrixInventoryPrice + TotalInventoryPrice;
          
          BeginningInventory = BeginningInventory  + matrix[row][0];                       
          currentItemInventory[row][3] = matrix[row][0];                
          currentItemInventory[row][4] = matrix[row][3];
          currentItemInventory[row][5] = Integer.parseInt(ItemsMatrix[row][0]);
  
          
         for (int col = 0; col <3; col++)
               currentItemInventory[row][col] = matrix[row][col];

         Initcount++;
         
     }// Ends Loop
     
     
        }
        
        else 
        {
            int FoundItemID = 0;
             
     for( int row = 0; row < currentItemInventory.length; row++)
      
     {
         
        if(ItemID == currentItemInventory[row][5]) 
        {
               double  RunningTotalofprice;
               double RunningTotalInvetory = 0;
               FoundItemID = 1;
               //First I will add to Pieces Sold to Update the Report.
               //currentItemInventory[row][3] = currentPiecesSold;
               
               currentItemInventory[row][4] = currentItemInventory[row][4] + currentPiecesSold;
               
              //Second I will subtract from Pieces in store to Update the Report.
               
               //Check to see if number of items requested is greater than inventory
               if (currentPiecesSold  <= currentItemInventory[row][3])
               {
                   currentItemInventory[row][3] = currentItemInventory[row][3] - currentPiecesSold;
                   RunningTotalofprice = currentPiecesSold * currentItemInventory[row][2];
               RunningTotalMaxtrix =  RunningTotalMaxtrix +  RunningTotalofprice;
               
               
               //Third I will add to the Total number of Inventory  products to Update the Report. 
               
               RunningTotalInvetory = RunningTotalInvetory + currentPiecesSold;
              TotalNumItemsInStore =  TotalNumItemsInStore + RunningTotalInvetory;
                    
               }
               else 
               {
                   System.out.println("Inventory on stock is: " + currentItemInventory[row][3]
                           + " And less than requested item: "+ currentPiecesSold);
               }
              //Third I will add to the running Total Inventory price of the store products to Update the Report. 
    
        }
      
        
        }
     if(FoundItemID == 0)
        {
            JOptionPane.showMessageDialog(null, " Please try another ItemID ", " Invalid ItemID  ",
               JOptionPane.INFORMATION_MESSAGE);
            //String ErrorMessage = JOptionPane.showMessageDialog(, "Invalid ItemID");
        }
        
        }
        }
        
          public static void ItemSearch( double [][] matrix, String [][] ItemsMatrix , int ItemID , int currentPiecesSold )
        {
		
        {
     for( int row = 0; row < matrix.length; row++)
      
     {
          TotalInventoryPrice = matrix[row][0] * matrix[row][2];
          TotalMaxtrixInventoryPrice =  TotalMaxtrixInventoryPrice + TotalInventoryPrice;
          
          BeginningInventory = BeginningInventory  + matrix[row][0];
     
           
            
          currentItemInventory[row][3] = matrix[row][0];
          currentItemInventory[row][4] = 0;
          currentItemInventory[row][5] = Integer.parseInt(ItemsMatrix[row][0]);
          
          
          
         for (int col = 0; col < 3; col++)
				   currentItemInventory[row][col] = matrix[row][col];
				   Initcount++;
			 
     }// Ends Loop

        }
        
        if(Initcount > 0)
        {
           int FoundItemID = 0;  
           
           
     for( int row = 0; row < currentItemInventory.length; row++)
      
     {
        if(ItemID == currentItemInventory[row][5]) 
        {
           FoundItemID = 1;
           
              //Second I will subtract from Pieces in store to Update the Report.
               
               //Check to see if number of items requested is greater than inventory
               if (currentPiecesSold  <= currentItemInventory[row][3])
               {
                  // System.out.println("Inventory is in stock : " + currentItemInventory[row][3]);
                   //System.out.println("The selling price is : " + "$" + currentItemInventory[row][2]);
                   
                 String  FinalOutput = ("Inventory is in stock : " + currentItemInventory[row][3] + "\n"
                 + "The selling price is : " + "$" + currentItemInventory[row][2]);
                 
                  JOptionPane.showMessageDialog(null, FinalOutput, "Inventory Check ",
               JOptionPane.INFORMATION_MESSAGE);
               }
               else 
               {
                   System.out.println("Inventory on stock is: " + currentItemInventory[row][3]
                           + " And less than requested item: "+ currentPiecesSold);
               }              
        }
      
        
        }
        if(FoundItemID == 0)
        {
            JOptionPane.showMessageDialog(null, " Please try another ItemID ", " Invalid ItemID  ",
               JOptionPane.INFORMATION_MESSAGE);
            //String ErrorMessage = JOptionPane.showMessageDialog(, "Invalid ItemID");
        }
        }
        } 
}
